#include <string>
#include <iostream>
#include "E_Meeting.h"
using namespace std;

//Constructor
E_Meeting::E_Meeting(){
	this->whoAmI = EXTENDED;
}
//Destructor
E_Meeting::~E_Meeting(){
}

//Copy Constructor
E_Meeting::E_Meeting(const E_Meeting& em):Meeting(em.getStartHour(), em.getEndHour(),(string&) em.getSubject())
{
	this->listOfAttendees = em.listOfAttendees;
	this->whoAmI = EXTENDED;
}

//Constructor
E_Meeting::E_Meeting(float start_t,float end_t,string& subject,string& attendees):Meeting(start_t,end_t,subject)
{
	this->whoAmI = EXTENDED;
	while (attendees.find(",", 0) != string::npos)
	{
    int  pos = attendees.find(",", 0);    //store the position of the delimiter
    string s = attendees.substr(0, pos);  //get the token
    attendees.erase(0, pos + 1);          //erase it from the source
	this->listOfAttendees.push_back(s);   //and put it into the array
  }

  this->listOfAttendees.push_back(attendees);
}

void E_Meeting::printMeeting() const{
	Meeting::printMeeting();
	cout<<"List of attendees: "<<endl;
	if (this->listOfAttendees.empty())
		cout<<"No attendees"<<endl;
	else
	{
		list<string>::const_iterator it;
		for ( it = this->listOfAttendees.begin(); it != this->listOfAttendees.end(); it++)
			cout << *it << endl;
	}
}

const bool  E_Meeting::overlapWith(const Meeting& m) const{
	bool olap = false;
	if (Meeting::overlapWith((Meeting&)m)){
		if (m.getWhoAmI()==EXTENDED) {
		//check by attendees
		E_Meeting* em = (E_Meeting*)&m;
		list<string>::const_iterator iter_this;
		list<string>::const_iterator iter_outer;
		for ( iter_this = this->listOfAttendees.begin(); iter_this != this->listOfAttendees.end(); iter_this++) {
			for(iter_outer = em->listOfAttendees.begin(); iter_outer != em->listOfAttendees.end(); iter_outer++){
				olap = olap|| !((*iter_this).compare(*iter_outer)); //TODO: CHANGED
			}
		}
		}
	}
		 return olap;
}


const list<string> E_Meeting::getListOfAttendees() const{
	return this->listOfAttendees;
}

void E_Meeting::setListOfAttendees(const list<string>& l){
	this->listOfAttendees = l;
}
